package com.creed.energy.project.system.common.model;

import com.creed.energy.project.system.common.utils.JsonUtils;
import lombok.Data;
import lombok.Getter;

/**
 * @author btmood
 * @version 1.0
 * @apiNote 通用返回值
 * @since 2023-11-19 21:57
 */
@Getter
@Data
public class Result<T> {
    private String code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getDesc();
    }

    public Result<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JsonUtils.getInstance().serialize(this);
    }
}
